import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Index',
        redirect: {name: "Blogs"},
        meta: {
            title: '首页'
        }
    },
    {
        path: '/blogs',
        name: 'Blogs',
        component: () => import('../views/Blogs'),
        meta: {
            title: '首页'
        }
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/Login'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/search',
        name: 'BlogSearch',
        component: () => import('../views/BlogSearch'),
        meta: {
            title: '搜索'
        }
    },
    {
        path: '/searchBlogs',
        name: 'SearchBlogs',
        component: () => import('../views/SearchBlogs'),
        meta: {
            title: '搜索',
            keepAlive: true
        }
    },
    {
        path: '/blog/add',
        name: 'BlogAdd',
        meta: {
            title: "新增文章",
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
        },
        component: () => import('../views/BlogEdit')
    },

    {
        path: '/blog/:blogId',
        name: 'BlogDetail',
        meta: {
            title: "文章详情",
        },
        component: () => import('../views/BlogDetail')
    },
    {
        path: '/blog/:blogId/edit',
        name: 'BlogEdit',
        meta: {
            title: "修改文章",
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
        },
        component: () => import('../views/BlogEdit')
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router
